const URL = 'https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1';

export async function getCurrencyList() {
  try {
    const response = await fetch(`${URL}/currencies.min.json`);
    const data = await response.json();

    return data;
  } catch (error) {
    console.log(error.message);
  }
}

export async function convertCurrency(from, to, amount) {
  try {
    const response = await fetch(`${URL}/currencies/${from}.json`);
    const data = await response.json();

    return data[from][to] * amount;
  } catch (error) {
    console.log(error.message);
  }
}
